package utils.animate
{
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.TimerEvent;

	public class AlphaMoveTween extends EventDispatcher
	{
		private var tweenLight:TweenLight;
		private var tweenProperty:TweenProperty;
		private var _target:DisplayObject;
		private var alphaTime:int;
		
		public function AlphaMoveTween()
		{
			initTweens();	
		}
		
		private function initTweens():void
		{
			tweenLight = new TweenLight();
			tweenLight.duration = 2;
			tweenLight.addEventListener(Event.COMPLETE,onTweenLightComplete);
			
			tweenProperty = new TweenProperty();
			tweenProperty.duration = .5;
			tweenProperty.addEventListener(Event.COMPLETE,onTweenPropertyComplete);
		}
		
		private function onTweenLightComplete(event:Event):void
		{
			if (_target)
			{
				tweenProperty.setTarget(_target,"alpha",1,0);
				tweenProperty.start();
			}
			
		}
		
		private function onTweenPropertyComplete(event:Event):void
		{
			stop();
			dispatchEvent(new Event(Event.COMPLETE));
			
		}
		
		public function set duration(v:Number):void
		{
			tweenLight.duration = v ;
		}
		
		public function get target():DisplayObject
		{
			return _target;
		}
		
		public function setTarget(target:DisplayObject,fx:Number,fy:Number,tx:Number,ty:Number):void
		{
			_target = target;
			//tweenProperty.setTarget(target,"alpha",0,1);
			tweenLight.setTarget(target,fx,fy,tx,ty);
			alphaTime = 0;
		}
		
		public function start():void
		{
			tweenLight.start();
		}
		
		public function stop():void
		{
			tweenProperty.stop();
			tweenLight.stop();
		}
		
		public function destroy():void
		{
			tweenLight.removeEventListener(Event.COMPLETE,onTweenLightComplete);
			tweenProperty.removeEventListener(Event.COMPLETE,onTweenPropertyComplete);
			tweenLight.destroy();
			tweenProperty.destroy();
			tweenLight = null;
			tweenProperty = null;
			_target = null;
		}
	}
}